package com.cares.event.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.sh.cares.dao.orm.hibernate.query.SafeDetachedCriteria;
import cn.sh.cares.dao.orm.hibernate.query.SafeRestrictions;

import com.cares.common.dao.impl.JsflowDaoImpl;
import com.cares.event.dao.EventExecutionDao;
import com.cares.event.dto.EventExecutionDto;
import com.cares.event.entity.TEventExecution;

@Repository("eventExecutionDao")
public class EventExecutionDaoImpl extends JsflowDaoImpl implements
		EventExecutionDao {
	/**
	 * 查询流程实例运行
	 * @param jsflowProcessVO
	 */
	public  TEventExecution getEventExecution(long executionId){
		return getEntityManager().get(TEventExecution.class, executionId);
	}

	/**
	 * 保存流程实例运行
	 * @param jsflowProcessVO
	 */
	public void saveEventExecution(TEventExecution tEventExecutionVO){
		getEntityManager().save(tEventExecutionVO);
	}
	
	/**
	 * 更新流程实例运行
	 * @param jsflowProcessVO
	 */
	public void updateEventExecution(TEventExecution tEventExecutionVO){
		getEntityManager().update(tEventExecutionVO);
	}
	
	/**
	 * 删除流程实例运行
	 * @param executionId
	 */
	public void deleteEventExecution(long executionId){
		getEntityManager().delete(TEventExecution.class, executionId);
	}
	
	
	/**
	 *查找指定事件流的执行任务
	 * @param jsflowProcessVO
	 */
	public List<TEventExecution> queryEventExecutions(EventExecutionDto eventExecutionDto){
		SafeDetachedCriteria criteria = SafeDetachedCriteria.forClass(TEventExecution.class);
		if(null != eventExecutionDto.getEventFlowId()){
			criteria.add(SafeRestrictions.equal("jsflowId", eventExecutionDto.getEventFlowId()));
		}
		if(null != eventExecutionDto.getActivityName()){
			criteria.add(SafeRestrictions.equal("activityName", eventExecutionDto.getActivityName()));
		}
		return getEntityManager().queryForListByCriteria(TEventExecution.class, criteria);
	}
	
	/**
	 * 查找所有的事件流程执行信息
	 * @return
	 */
	public List<TEventExecution> queryAllEventExecutions(){
		SafeDetachedCriteria criteria = SafeDetachedCriteria.forClass(TEventExecution.class);
		return getEntityManager().queryForListByCriteria(TEventExecution.class, criteria);
	}

}
